package com.fjeld.server.ssl.impl;

import com.fjeld.middleware.activemq.HeartbeatListener;
import com.fjeld.middleware.activemq.MessagesListener;
import com.fjeld.middleware.constants.PropertiesManager;
import com.fjeld.server.ssl.ServerStackLayer;
import com.fjeld.client.gui.ManagementGUI;
import org.apache.log4j.Logger;

import javax.jms.JMSException;
import javax.swing.*;

/**
 * Created by IntelliJ IDEA.
 * User: fjeld
 * Date: 11/12/2011
 * Time: 21:29
 * To change this template use File | Settings | File Templates.
 */
public class ManagementGUIStack extends AbstractServerStack implements ServerStackLayer
{
    private static final Logger LOGGER = Logger.getLogger(ManagementGUIStack.class);

    private HeartbeatListener hbListener;
    private MessagesListener msgListener;

    public ManagementGUIStack() throws JMSException
    {
        hbListener = new HeartbeatListener("PUBLISH.HEARTBEAT.>", serverName + ".HeartbeatListener");

        String topicMessageRequest = PropertiesManager.getProperties().getProperty("Topic.All.Prefix") + ".>";
        msgListener = new MessagesListener(topicMessageRequest, serverName + ".MessageListener");

        // Don't start it listeners yet as it makes it difficult for swing
        // utilities to work properly on startup
        //hbListener.startConnection();

        LOGGER.info("Finished initialising");
        ManagementGUI.main(hbListener, msgListener, null);

        SwingUtilities.invokeLater(new Runnable()
        {
            public void run()
            {
                hbListener.startConnection();
                msgListener.startConnection();
            }
        });
    }
}
